<template>
	<view class="content">
		<view class="main">
			<view class="info">
				<view class="info2">原密码</view>
				<view class="info3">
					<input type="password" @input="password" placeholder="请填写原密码" />
				</view>
			</view>
			<view class="info">
				<view class="info2">新密码</view>
				<view class="info3">
					<input type="password" @input="newpwd" placeholder="请填写新密码,6-30个字符之间" />
				</view>
			</view>
			<view class="info">
				<view class="info2">确认密码</view>
				<view class="info3">
					<input type="password" @input="qrpwd" placeholder="请再次输入新密码进行确认" />
				</view>
			</view>
			
			<view class="info4" @click="baocun">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	var app=getApp();
	export default {
		data() {
			return {
				uid:0,
				pwd:{password:'',newpwd:'',qrpwd:''}
			}
		},
		onLoad(op) {
			const uid = uni.getStorageSync('uid');
			if(app.isBlank(uid)==true){
				app.error_msg("请先登录");
			}
			this.uid=uid;
		},
		methods: {
			baocun(){
				var that=this;
				if(app.isBlank(this.pwd.password)==true){
					uni.showToast({
					    title: "请填写原密码",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(app.isBlank(this.pwd.newpwd)==true){
					uni.showToast({
					    title: "请填写新密码",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				if(this.pwd.newpwd.length<6 || this.pwd.newpwd.length>30){ 
					uni.showToast({
					    title: "新密码在6-30个字符之间",
						icon:'none',
					    duration: 1500
					});
					return false; 
				} 
				if(this.pwd.newpwd!=this.pwd.qrpwd){
					uni.showToast({
					    title: "两次输入密码不一致",
						icon:'none',
					    duration: 1500
					});
					return false;
				}
				uni.showLoading({
				    title: '请求中'
				});
				var u=JSON.stringify(that.pwd);
				u=JSON.parse(u)
				u.uid=that.uid;
				uni.request({
				    url: app.globalData.url+"user/pwd",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: u,
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							uni.showToast({
							    title: res.data.msg,
								icon:'none',
							    duration: 1500
							});
							return false;
						}
						uni.showToast({
						    title: res.data.msg,
							icon:'success',
						    duration: 1000
						});
						setTimeout(function(){
							uni.switchTab({
							    url: '/pages/user/index'
							});
						},1000)
						
				    }
				});
			},
			password: function(event) {
			    this.pwd.password = event.target.value
			},
			newpwd: function(event) {
			    this.pwd.newpwd = event.target.value
			},
			qrpwd: function(event) {
			    this.pwd.qrpwd = event.target.value
			}
		}
	}
</script>

<style>
	.picker{width:100%;height:40px;line-height: 40px;text-align: right;}
	.info4{width:94%;margin:0px 3%;height:40px;line-height: 40px;text-align: center;background-color: #05c160;border-radius: 5px;margin-top: 20px;color:#fff;}
	.info3 image{width:45px;height:45px;margin-top: 7.5px;border-radius: 50%;float: right;}
	.info3 input{width:100%;height:40px;text-align: right;font-size: 0.85rem;color:#333;}
	.info3{width:100%;height:40px;flex:1;}
	.info2{width:80px;height:40px;line-height: 40px;margin-right: 5px;}
	.info{width:94%;padding: 0px 3%;display: flex;border-bottom: 1px rgb(245, 245, 245) solid;}
	.main{width:100%;}
</style>
